package c.mars.tower_of_hanoi.menu;

import android.content.Context;
import android.opengl.GLES20;
import android.opengl.Matrix;

import javax.microedition.khronos.opengles.GL10;
import javax.microedition.khronos.egl. EGLConfig;

import c.mars.tower_of_hanoi.common.*;
import c.mars.tower_of_hanoi.game.Triangle;

public class MenuRenderer extends Renderer
{
	TexturedSquareButton mButton3;
	Triangle mTriangle;
	
	@Override
	public void onSurfaceCreated(GL10 unused, EGLConfig config) {
        // Set the background frame color
        GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
		
        mButton3 = new TexturedSquareButton();
		mTriangle = new Triangle();
    }

	// new comment
	
	@Override
    public void onDrawFrame(GL10 unused) {
        // Redraw background color
        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
		
        // Set the camera position (View matrix)
        Matrix.setLookAtM(mViewMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);

        // Calculate the projection and view transformation
        Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mViewMatrix, 0);

//        For now, draw didn't do anything. So, for mockup I display triangles
//        mButton3.draw(mMVPMatrix);
        Matrix.translateM(mMVPMatrix, 0, -1.0f, 0, 0); // translation to the left
        mTriangle.draw(mMVPMatrix, 1);
        
        Matrix.translateM(mMVPMatrix, 0, 0.0f, 0, 0); // translation to the left
        mTriangle.draw(mMVPMatrix, 2);
        
        Matrix.translateM(mMVPMatrix, 0, 1.0f, 0, 0); // translation to the left
        mTriangle.draw(mMVPMatrix, 3);
    }

	@Override
    public void onSurfaceChanged(GL10 unused, int width, int height) {
        GLES20.glViewport(0, 0, width, height);
        
        float ratio = (float) width / height;
        Matrix.frustumM(mProjectionMatrix, 0, -ratio, ratio, -1, 1, 3, 7);
    }
}
